/*
 * Copyright 2008-2012 Centro Andaluz de Innovación y Tecnologías de la
 * Información y las Comunicaciones (CITIC). All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 * Please contact CITIC - Edificio CITIC, C/ Marie Curie, 6 Parque
 * Tecnológico de Andalucía 29590 - Campanillas, Málaga, Spain
 * or visit www.citic.es, if you need additional information or
 * have any questions.
 */

package es.citic.puedes.youtube.testhelp;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;

import es.citic.puedes.youtube.IYouTubeManager;
import es.citic.puedes.youtube.YouTubeException;
import es.citic.puedes.youtube.model.Category;
import es.citic.puedes.youtube.model.OrderBy;
import es.citic.puedes.youtube.model.YouTubeResult;
import es.citic.puedes.youtube.model.YouTubeType;
import es.citic.puedes.youtube.model.YouTubeVideoMinimal;

public class YouTubeSearchTest {

	public static void runYouTubeSearchTest(IYouTubeManager ytm, YouTubeType type, OrderBy order) throws SecurityException, YouTubeException {
		YouTubeResult result = new YouTubeResult();

		// test for searching videos
		List<String> keywordsToSearch = new ArrayList<String>();
		keywordsToSearch.add("shakira");
		result = ytm.search(type, order, keywordsToSearch);
		System.out.println("SEARCH:");
		YouTubePrinterTestMethods.printModelResultList(result);
		
		Assert.assertNotNull(result);
		Assert.assertTrue(result.getVideos().size() > 0);
	}

	public static void runYouTubeExploreTest(IYouTubeManager ytm, YouTubeType type, Category category, OrderBy order) throws SecurityException, YouTubeException {
		List<YouTubeVideoMinimal> videoMinimalList = null;

		// test for exploring videos
		List<String> keywordsToExplore = new ArrayList<String>();
		keywordsToExplore.add("futbol");

		//explores and gets the first hundred elements
		videoMinimalList = ytm.explore(category, order, keywordsToExplore);
		YouTubePrinterTestMethods.printModelVideoMinimalList(videoMinimalList, "EXPLORE:");
		
		Assert.assertNotNull(videoMinimalList);
		Assert.assertTrue(!videoMinimalList.isEmpty());
	}

	public static void runYouTubeGetVideoTest(IYouTubeManager ytm, String videoID) throws SecurityException, YouTubeException {
		// test for get videos URL
		String result = ytm.getVideo(videoID).getUrl();
		System.out.println("VideoURL:" + result);
		Assert.assertNotNull(result);
		Assert.assertTrue(!result.isEmpty());
	}

	public static void runYouTubeSearchPaginationTest(IYouTubeManager ytm, YouTubeType type, OrderBy order) throws SecurityException, YouTubeException {
		YouTubeResult result = new YouTubeResult();

		//searches by paging
		List<String> keywordsToSearch = new ArrayList<String>();
		keywordsToSearch.add("shakira");
		result = ytm.search(type, order, keywordsToSearch,1,8);
		System.out.println("SEARCH by PAGING:");
		YouTubePrinterTestMethods.printModelResultList(result);
		
		Assert.assertNotNull(result);
		Assert.assertTrue(result.getVideos().size() > 0);
	}

	public static void runYouTubeExplorePaginationTest(IYouTubeManager ytm, YouTubeType type, Category category, OrderBy order) throws SecurityException, YouTubeException {
		List<YouTubeVideoMinimal> videoMinimalList = null;

		//explores by paging
		List<String> keywordsToExplore = new ArrayList<String>();
		keywordsToExplore.add("futbol");
		videoMinimalList = ytm.explore(category, order, keywordsToExplore,1,8);
		YouTubePrinterTestMethods.printModelVideoMinimalList(videoMinimalList, "EXPLORE:");		

		Assert.assertNotNull(videoMinimalList);
		Assert.assertTrue(!videoMinimalList.isEmpty());
	}
}
